package logs

import (
	"github.com/stretchr/testify/assert"
	"go.uber.org/zap"
	"net/http"
	"os"
	"testing"
)

func TestMain(m *testing.M) {
	LogLevel = "debug"
	LoggersInit()
	os.Exit(m.Run())
}

func TestParseAndSetReverseLevel(t *testing.T) {

	AtomLevel = zap.NewAtomicLevel()

	t.Parallel()
	tests := []struct {
		level   string
		wantErr bool
	}{
		{level: "debug"},
		{level: "info"},
		{level: "warn"},
		{level: "error"},
		{level: "dpanic"},
		{level: "panic"},
		{level: "fatal"},
		{level: "err", wantErr: true},
	}
	for _, tt := range tests {
		t.Run(tt.level, func(t *testing.T) {
			if err := parseAndSetReverseLevel(tt.level); (err != nil) != tt.wantErr {
				t.Errorf("parseAndSetReverseLevel() error = %v, wantErr %v", err, tt.wantErr)
			}
		})
	}
}

func TestHandle(t *testing.T) {
	db := IsDebugMode()
	mux := http.ServeMux{}
	ChangeDebugLevelServerStart("8888", &mux)
	assert.Equal(t, false, db)
}
